package com.shengsiyuan.nio;

import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * Created by deng_wb on 2019/8/15
 */
public class NioTest3 {
    public static void main(String[] args)throws Exception {
        FileOutputStream fileOutputStream = new FileOutputStream("NioTest3.txt");
        FileChannel fileChannel = fileOutputStream.getChannel();
        ByteBuffer buffer = ByteBuffer.allocate(512);
        byte[] message = "hello world welcome, nihao".getBytes();

        for (int i = 0; i < message.length; i++) {

            buffer.put(message[i]);
        }
        buffer.flip();
        fileChannel.write(buffer);
        fileOutputStream.close();
    }

}
